package com.book.utils;


import com.book.exception.GlobalException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class TransitionUtils {


    public static <T> List<T> mapTransitionArray(Map<Long, T> map){
        if(map == null){
            return null;
        }
        List<T> list = new ArrayList<>();
        map.values().forEach(e -> list.add(e));
        return list;
    }

    public static String objectTransitionArray(Object object){
        if(object == null) return null;
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            throw new GlobalException(500,"JSON类型转换异常！！");
        }
    }

}
